package com.toutiao.issue

import scala.collection.mutable.{HashMap => HMap}

import org.apache.log4j.Logger

class SimpleModel(minV:Double,minS:Double) {
  
  
  private
  val _log = Logger.getLogger(this.getClass.getName)
  
  private
  val M1 = new HMap[String,Long]
  private
  val M2 = new HMap[Long,String]
  private
  var N1 = 0
  private
  var N2 = 0
  
  val mData = new SimpleCollector(minV)
  _log.info("Naive WAND S ")
  
  def processOne(m:Document) = synchronized {
    if (!M1.contains(m.name)){
      N2 += 1
      M1(m.name) = N2
      M2(N2) = m.name
      val r = mData.process(M1, M2, m, minS)
      r
    }
    else {
      ""
    }
  }
  
  def run(data:Array[Document]) = {
    var cnt = 0
    for (m <- data){
      cnt += 1
      if (cnt % 1000 == 0){
        _log.info(cnt + " "+mData.size)
      }
      processOne(m)
    }
  }
  
  def save(location:String) {
    Data.saveTopic(mData.data, location)
  }

}
